﻿using System;
using System.Collections.Generic;
using System.Web;
using SAS.Core;
using SAS.Core.Entity;
using SAS.WebSite.BaseClasses;

namespace SAS.WebSite.Service
{
    public partial class Services : BasePage
    {
        /*The common services, properties and private methods are defined here */

        private new static User User
        {
            get
            {
                return HttpContext.Current.Session["User"] == null
                           ? new User()
                           : (User) HttpContext.Current.Session["User"];
            }
        }

        private static string ClientIp
        {
            get
            {   
                HttpRequest currentRequest = HttpContext.Current.Request;
                string ipAddress = currentRequest.ServerVariables["HTTP_X_FORWARDED_FOR"];

                if (ipAddress == null || ipAddress.ToLower() == "unknown")
                    ipAddress = currentRequest.ServerVariables["REMOTE_ADDR"];

                return ipAddress; 
            }
        }


        protected void Page_Load(object sender, EventArgs e)
        {
            int fileCount = HttpContext.Current.Request.Files.Count;
        }

        private static AdvSearch GetAdvanceSearch(object json)
        {
            dynamic parameters = json;

            AdvSearch advSearch = new AdvSearch();

            foreach (KeyValuePair<string, object> parameter in parameters)
            {
                switch (parameter.Key)
                {
                    case "page":
                        advSearch.PageNumber = Convert.ToInt32(parameter.Value.ToString());
                        break;
                    case "rows":
                        advSearch.PageSize = Convert.ToInt32(parameter.Value.ToString());
                        break;
                    case "sidx":
                        advSearch.OrderBy = parameter.Value.ToString();
                        break;
                    case "sord":
                        advSearch.Sord = parameter.Value.ToString();
                        break;
                    case "_search":
                        //bool filtered = Convert.ToBoolean(parameter.Value.ToString());
                        break;
                    case "nd":
                        advSearch.Nd = parameter.Value.ToString();
                        break;
                    default:
                        advSearch.Paramvals.Add(parameter.Key, parameter.Value);
                        break;
                }
            }

            return advSearch;
        }
      
    }
}